package com.project.web.order.controller.common;

import com.alibaba.fastjson.JSONObject;
import com.project.common.core.utils.apple.ApplePayUtil;
import com.project.common.core.utils.exception.Result;
import com.project.web.order.service.app.MbrOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * Apple Pay订单数据验证
 *
 * @author WYY
 * @date 2021/02/18
 */
@ApiIgnore
@Controller("applePayNotifyController")
@RequestMapping("/order/anon/appNotify")
public class ApplePayNotifyController extends BaseController {

    private static final long serialVersionUID = 108856281010693726L;

    @Resource(name = "mbrOrderServiceImpl")
    private MbrOrderService mbrOrderService;

    /**
     * Apple Pay订单数据验证
     *
     * @param receiptData 数据验证
     * @return
     */
    @ResponseBody
    @RequestMapping("/verify")
    public Result<JSONObject> appPay(String receiptData) {
        log.info("\r\n ********************** Apple Pay receiptData：{} **************************", receiptData);
        JSONObject jsonObject = ApplePayUtil.verifyPayData(receiptData);
        log.info("\r\n ********************** Apple Pay verify：{} **************************", jsonObject.toJSONString());
        return getResult(jsonObject);
    }
}
